package com.bnz.staticpage.controller;

import com.bnz.staticpage.dao.TbItemRepository;
import com.bnz.staticpage.entity.TbItem;
import com.bnz.staticpage.service.ItemService;
import com.bnz.staticpage.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @author xy
 * @date 2022/11/23
 */
@RestController
@RequestMapping("/page")
public class PageController {

    @Autowired
    private PageService pageService;
    @Autowired
    private ItemService itemService;
    @Autowired
    private TbItemRepository tbItemRepository;
    @RequestMapping("/createHtml/{id}")
    public void createHtml(@PathVariable Long id) throws IOException {
        pageService.createHtml(id);
    }
    @RequestMapping("/all")
    public List<TbItem> queryAll(){
        return itemService.queryAll();
    }

    @RequestMapping("/items/{id}")
    public List<TbItem> items(@PathVariable Long id ){
       return tbItemRepository.findByGoodsIdOrderByIsDefaultAsc(id);
    }
}
